package cn.stylefeng.guns.modular.hx.storage.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.hx.storage.entity.HxCollectionLocation;
import cn.stylefeng.guns.modular.hx.storage.mapper.HxCollectionLocationMapper;
import cn.stylefeng.guns.modular.hx.storage.model.params.HxCollectionLocationParam;
import cn.stylefeng.guns.modular.hx.storage.model.result.HxCollectionLocationResult;
import  cn.stylefeng.guns.modular.hx.storage.service.HxCollectionLocationService;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lww
 * @since 2024-01-02
 */
@Service
public class HxCollectionLocationServiceImpl extends ServiceImpl<HxCollectionLocationMapper, HxCollectionLocation> implements HxCollectionLocationService {

    @Override
    public void add(HxCollectionLocationParam param){
        HxCollectionLocation entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(HxCollectionLocationParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(HxCollectionLocationParam param){
        HxCollectionLocation oldEntity = getOldEntity(param);
        HxCollectionLocation newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public HxCollectionLocationResult findBySpec(HxCollectionLocationParam param){
        return this.baseMapper.findByLocationResult(param);
    }

    @Override
    public List<HxCollectionLocationResult> findListBySpec(HxCollectionLocationParam param){
        return this.baseMapper.customList(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(HxCollectionLocationParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<HxCollectionLocationResult> findLocation(HxCollectionLocationParam hxCollectionLocationParam) {
        return this.baseMapper.findLocation(hxCollectionLocationParam);
    }

    @Override
    public List<HxCollectionLocationResult> getStockPortByUnit(HxCollectionLocationParam hxCollectionLocationParam) {
        return this.baseMapper.getStockPortByUnit(hxCollectionLocationParam);
    }

    @Override
    public void deliveryTray(HxCollectionLocationParam hxCollectionLocationParam) {
        this.baseMapper.deliveryTray(hxCollectionLocationParam);
    }

    @Override
    public void clear(HxCollectionLocationParam hxCollectionLocationParam) {
         this.baseMapper.clear(hxCollectionLocationParam);
    }

    @Override
    public List <HxCollectionLocationResult> find(HxCollectionLocationParam hxCollectionLocationParam, String condition) {
        return this.baseMapper.find(hxCollectionLocationParam, condition);
    }

    private Serializable getKey(HxCollectionLocationParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private HxCollectionLocation getOldEntity(HxCollectionLocationParam param) {
        return this.getById(getKey(param));
    }

    private HxCollectionLocation getEntity(HxCollectionLocationParam param) {
        HxCollectionLocation entity = new HxCollectionLocation();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
